<template>
	<view class="comp-content">
		<view class="logBox" v-for="(logList,time) in state.list" :key="time" >
			<view class="logBox-time">
				{{timeFormat(time,'mm/dd日')}}
			</view>
			<view class="listBox">
				<view class="listBox-item ss-flex" v-for="item in logList" :key="`${time}-${item.id}`" @click="sheep.$router.go('/pages/goods/index',{id:item.goods.id})">
					<image class="listBox-item-img ss-m-r-20" :src="sheep.$url.cdn(item.goods.image)" mode="aspectFill" />
					<view class="listBox-item-right ss-flex-1 ss-flex-col ss-row-between">
						<view class="right-title ss-line-1">
							{{item.goods.title}}
						</view>
						<view class="right-bottom ss-flex ss-row-between">
							<view class="right-bottom-price">
								<text class="icon">￥</text>
								<text class="price ss-m-r-10">
									{{item.goods.price.length >1 ? item.goods.price.join('~'):item.goods.price[0]}}
								</text>
								<text class="dsj">到手价</text>
							</view>
							<view class="right-bottom-btn ss-flex ">
								<button class="ss-reset-button similar ss-flex">看相似</button>
								<view class="cart ss-flex ss-row-center">
									<uni-icons type="plusempty" size="12" color="#F6704F"/>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view  v-if="Object.keys(state?.list).length != 0"  @click="getList">
			<uni-load-more  :contentText="{
				contentdown:'点击加载更多'
			}"  :status="state.more"/>
		</view>
		<s-empty v-else-if="state.more == 'noMore'" :icon="sheep.$url.cdn('/mengchong/soldout-empty.png')" text="暂无记录"/>
	</view>
</template>

<script setup>
	import sheep from '@/sheep';
	import { reactive, computed,nextTick,onMounted } from 'vue'
	import { onLoad, onShow, onHide ,onReachBottom} from '@dcloudio/uni-app';
	import {timeFormat} from "@/sheep/helper/index"
	const emit = defineEmits(['set'])
	const props = defineProps({
		data:{
			type:Object,
			default:()=>({})
		}
	})
	const state = reactive({
		page:0,
		more:'more',
		list:{}
	})
	onMounted(()=>{
		getList()
	})
	onReachBottom(()=>{
		
	})
	
	async function getList(){
		if(state.more == 'noMore') return uni.showToast({
			title:'没有更多了',
			icon:'none'
		})
		state.more = 'loading'
		let {error,data} = await sheep.$api.user.log.goodsLog({
			list_rows:6,
			page:state.page + 1
		})
		if(error == 0){
			data.data.forEach((log)=>{
				let time = log.update_time.split(' ')[0]
				if(state.list[time]){
					state.list[time].push(log)
				}else{
					state.list[time] = [log]
				}
			})
			state.page = data.current_page
			state.more = data.data.length!=data.per_page  ? 'noMore':'more'
		}else{
			state.more = 'noMore'
		}
	}

	
</script>

<style lang="scss" scoped>
	.comp-content{
		.logBox{
			.logBox-time{
				margin: 20rpx 38rpx;
				width: 278rpx;
				height: 40rpx;
				font-family: Source Han Sans;
				font-size: 30rpx;
				font-weight: normal;
				line-height: 40rpx;
				letter-spacing: normal;
				color: #000000;
			}
			.listBox{
				.listBox-item{
					width: 710rpx;
					box-sizing: border-box;
					border-radius: 10rpx;
					background: #FFFFFF;
					margin: 20rpx 20rpx;
					height: 189rpx;
					padding: 14rpx 0 14rpx 20rpx;
					.listBox-item-img{
						width: 160rpx;
						min-width: 160rpx;
						height: 160rpx;
						border-radius: 10rpx;
					}
					.listBox-item-right{
						height: 160rpx;
						.right-title{
							font-family: Source Han Sans;
							font-size: 30rpx;
							font-weight: 500;
							line-height: 132.75%;
							letter-spacing: normal;
							color: #000000;
						}
						.right-bottom{
							.right-bottom-price{
								.icon{
									font-family: Source Han Sans;
									font-size: 22rpx;
									font-weight: 500;
									line-height: normal;
									text-align: center;
									letter-spacing: normal;
									color: #F43B2C;
								}
								.price{
									font-family: Source Han Sans;
									font-size: 36rpx;
									font-weight: bold;
									line-height: normal;
									letter-spacing: normal;
									color: #F6481E;
								}
								.dsj{
									font-family: Source Han Sans;
									font-size: 28rpx;
									font-weight: normal;
									line-height: 132.75%;
									letter-spacing: normal;
									color: #F6481E;
								}
							}
							.right-bottom-btn{
								.similar{
									margin-right: 10rpx;
									padding: 0 8rpx;
									height: 46rpx;
									border-radius: 4rpx;
									background: rgba(216, 216, 216, 0);
									box-sizing: border-box;
									border: 1rpx solid #C7C7C7;
									
									font-family: Source Han Sans;
									font-size: 28rpx;
									font-weight: normal;
									vertical-align: middle;
									color: #636363;
								}
								.cart{
									margin-right: 10rpx;
									width: 46rpx;
									min-width: 46rpx;
									height: 46rpx;
									border-radius: 50%;
									background: #FBEBEC;
								}
							}
						}
					}
				}
			}
		}
	}
</style>